package com.woniu.zsd.platform.controller;


import com.woniu.zsd.common.util.Result;
import com.woniu.zsd.platform.annotation.RequirePermission;
import com.woniu.zsd.platform.annotation.RequireRole;
import com.woniu.zsd.platform.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangtao
 * @since 2025年02月18日
 */
@RestController("plateFormRoleController")
@RequestMapping("/role")
@Api(tags = "角色管理")
public class RoleController {
    @Resource
    private RoleService roleService;

    @GetMapping("/selectAllRole")
    @ApiOperation(value = "查询所有角色", notes = "查询所有角色")
    @RequireRole({"超级管理员"})
    @RequirePermission("查询所有角色")
    public Result selectAllRole() throws Exception {
        return Result.success("查询所有角色成功", roleService.selectAllRole());
    }


    @PostMapping("/addRole")
    @ApiOperation(value = "添加角色", notes = "添加角色")
    @RequireRole({"超级管理员"})
    @RequirePermission("添加角色")
    public Result addRole( String roleName) throws Exception {
        roleService.addRole(roleName);
        return Result.success("添加角色成功");
    }

    @PostMapping("/deleteRole")
    @ApiOperation(value = "删除角色", notes = "删除角色")
    @RequireRole({"超级管理员"})
    @RequirePermission("删除角色")
    public Result deleteRole(Integer roleId) throws Exception {
        roleService.deleteRole(roleId);
        return Result.success("删除角色成功");
    }
}

